package pikes.peak;

import java.util.Collections;
import java.util.Map;

import org.springframework.web.servlet.support.RequestContext;

import pikes.uri.RelativeURI;
import pikes.uri.URI;

public class InternalURI implements RequestProperty<URI> {

	private RequestProperty<CharSequence> relativePath = null;

	private RequestProperty<Map<CharSequence, CharSequence>> parameters = new RequestIndependentProperty<Map<CharSequence, CharSequence>>(
			Collections.EMPTY_MAP);

	public InternalURI(String relativePath) {
		super();
		this.relativePath = new ApplicationContextMessageProvider(relativePath);
	}

	public InternalURI(String relativePath, RequestProperty<Map<CharSequence, CharSequence>> parameters) {
		this(relativePath);
		this.parameters = parameters;
	}

	public InternalURI(String relativePath, Map<CharSequence, CharSequence> parameters) {
		this(relativePath, new RequestIndependentProperty<Map<CharSequence, CharSequence>>(parameters));
	}

	public URI getValue(Map model, RequestContext requestContext) throws Exception {
		RelativeURI contextPath = new RelativeURI(requestContext.getContextPath());
		return new RelativeURI(contextPath, relativePath.getValue(model, requestContext), parameters.getValue(model,
				requestContext));
	}
}
